package com.atguigu.exer2;

public class Student implements Comparable {
    private String name;
    private int score;
    private int id;

    public Student() {
    }

    public Student(String name, int score, int id) {
        this.name = name;
        this.score = score;
        this.id = id;
    }

    public String getName() {

        return name;
    }

    public int getScore() {

        return score;
    }

    public int getId() {

        return id;
    }

    public void setName(String name) {

        this.name = name;
    }

    public void setScore(int score) {

        this.score = score;
    }

    public void setId(int id) {

        this.id = id;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                ", id=" + id +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (getScore() != student.getScore()) return false;
        if (getId() != student.getId()) return false;
        return getName() != null ? getName().equals(student.getName()) : student.getName() == null;
    }

    @Override
    public int hashCode() {
        int result = getName() != null ? getName().hashCode() : 0;
        result = 31 * result + getScore();
        result = 31 * result + getId();
        return result;
    }

    @Override
    public int compareTo(Object o) {
        if(o instanceof Student) {
            Student s1 = (Student) o;
            int num =s1.score - score;
            if (num != 0) {
                return num;
            } else {
                return this.name.compareTo(s1.name);
            }
        }
        throw new RuntimeException("输入数据不匹配");
    }
}
